<template>
  <div class="word-detail-container">
    <!-- 顶部区域 -->
    <div class="top-bar">
      <div class="word-title">
        <div class="word-main">energy</div>
        <div class="word-phonetic">/ˈenərdʒi/ <span class="sound-icon">🔊</span></div>
      </div>
      <img src="@/assets/xx.png" class="top-right-icon" alt="xx" />
    </div>

    <!-- 词义部分 -->
    <div class="word-meanings">
      <div class="word-nature">
        n. 活力；能量；能源；精力；【护】能量；【化】能量，活化能；【物】能量；干劲
      </div>
    </div>

    <!-- 词根助记 -->
    <div class="word-root-box">
      <span class="root-label">词根助记</span>
      <span class="root-content">en在...上 + ergy功 → 做功 → energy 能量</span>
    </div>

    <!-- 例句部分 -->
    <div class="sentence-box">
      <div class="en-sentence">The man is full of <span class="highlight">energy</span> every morning.</div>
      <div class="cn-sentence">这个人每天早晨都精力充沛。</div>
      <img src="@/assets/8.png" class="sentence-img" alt="energy" />
    </div>

    <!-- tab和内容盒子 -->
    <div class="tab-content-box">
      <div class="tab-bar-group">
        <div class="tab-bar-row">
          <span class="tab" :class="{active: activeTab === 0}" @click="activeTab = 0">词组搭配</span>
          <span class="tab" :class="{active: activeTab === 1}" @click="activeTab = 1">英文释义</span>
          <span class="tab" :class="{active: activeTab === 2}" @click="activeTab = 2">近义词</span>
          <span class="tab" :class="{active: activeTab === 3}" @click="activeTab = 3">反义词</span>
        </div>
        <div class="tab-bar-row">
          <span class="tab" :class="{active: activeTab === 4}" @click="activeTab = 4">形近词</span>
        </div>
      </div>

      <!-- Tab内容区域 -->
      <div class="tab-content">
        <!-- 词组搭配内容 -->
        <div v-if="activeTab === 0" class="collocation-list">
          <div class="collocation-item">
            <div class="collocation-en">energy efficient</div>
            <div class="collocation-cn">节能</div>
          </div>
          <div class="collocation-item">
            <div class="collocation-en">energy consumption</div>
            <div class="collocation-cn">能量损耗</div>
          </div>
          <div class="collocation-item">
            <div class="collocation-en">new energy</div>
            <div class="collocation-cn">新能源</div>
          </div>
          <div class="collocation-item">
            <div class="collocation-en">energy conservation</div>
            <div class="collocation-cn">能量守恒；能源节约</div>
          </div>
          <div class="collocation-item">
            <div class="collocation-en">solar energy</div>
            <div class="collocation-cn">太阳能</div>
          </div>
        </div>

        <!-- 英文释义内容 (图一) -->
        <div v-if="activeTab === 1" class="english-meaning">
          n. the capacity of acting or being active
        </div>

        <!-- 近义词内容 (图二) -->
        <div v-if="activeTab === 2" class="two-column-list">
          <div class="two-column-item">activity</div>
          <div class="two-column-item">power</div>
          <div class="two-column-item">spirit</div>
          <div class="two-column-item">strength</div>
        </div>

        <!-- 反义词内容 (图三) -->
        <div v-if="activeTab === 3" class="two-column-list">
          <div class="two-column-item">inertia</div>
          <div class="two-column-item">lethargy</div>
          <div class="two-column-item">weakness</div>
        </div>

        <!-- 形近词内容 (图四) -->
        <div v-if="activeTab === 4" class="two-column-list">
          <div class="two-column-item">synergy</div>
          <div class="two-column-item">emerge</div>
          <div class="two-column-item">enemy</div>
        </div>
      </div>
    </div>

    <!-- 底部按钮栏 -->
    <div class="bottom-bar">
      <img src="@/assets/7.png" class="bottom-left-icon" alt="7" />
      <button class="next-btn" @click="goToNextWord">下一题</button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const activeTab = ref(0) // 默认显示词组搭配

function goToNextWord() {
  router.push({ name: 'danci' })
}
</script>

<style scoped>
.word-detail-container {
  background: #fff;
  min-height: 100vh;
  padding-bottom: 80px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 18px 0 18px;
}
.word-title {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.word-main {
  font-size: 2.3rem;
  font-weight: bold;
  color: #222;
}
.word-phonetic {
  font-size: 1.1rem;
  color: #888;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sound-icon {
  font-size: 1.2rem;
  color: #2979ff;
  margin-left: 4px;
}
.top-right-icon {
  width: 32px;
  height: 32px;
  margin-top: 4px;
}
.word-meanings {
  margin: 18px 18px 0 18px;
  color: #444;
  font-size: 1.05rem;
}
.word-nature {
  line-height: 1.7;
  text-align: left;
}
.word-root-box {
  background: #f7f7fa;
  border-radius: 10px;
  margin: 18px 18px 0 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
}
.root-label {
  background: #e6eaf3;
  color: #2979ff;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.95rem;
}
.root-content {
  color: #666;
}
.sentence-box {
  margin: 22px 18px 0 18px;
  background: #f7f7fa;
  border-radius: 10px;
  padding: 16px 14px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.en-sentence {
  font-size: 1.1rem;
  color: #222;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.en-sentence .highlight {
  color: #2979ff;
  font-weight: bold;
}
.cn-sentence {
  color: #888;
  font-size: 1rem;
  margin-bottom: 10px;
}
.sentence-img {
  width: 100%;
  max-width: 320px;
  border-radius: 8px;
  margin-top: 8px;
}
.tab-content-box {
  background: #f7f7fa; /* 灰色背景 */
  border-radius: 10px;
  /* height: 825px; 根据内容自适应高度 */
  margin: 22px 18px 0 18px; /* 保持与例句下方的间距 */
  padding: 18px; /* 内部留白 */
  display: flex;
  flex-direction: column;
}
.tab-bar-group {
  margin-bottom: 18px; /* Tab栏和内容之间的间距 */
}
.tab-bar-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}
.tab {
  padding: 6px 14px;
  border-radius: 16px;
  background: #fff;
  color: #888;
  font-size: 0.98rem;
  white-space: nowrap;
  cursor: pointer;
  border: none;
  outline: none;
  transition: background 0.2s, color 0.2s;
}
.tab.active {
  background: #f2f4f8;
  color: #222;
}
.tab-content {
  flex-grow: 1; /* 占据剩余空间 */
  overflow-y: auto; /* 允许垂直滚动 */
}
.collocation-item {
  display: flex;
  flex-direction: column;
  font-size: 1.05rem;
  margin-bottom: 10px;
  text-align: left;
}
.collocation-en {
  color: #222;
  /* min-width: 120px; */
}
.collocation-cn {
  color: #888;
  font-size: 0.98rem;
  margin-left: 0;
}
/* 英文释义样式 */
.english-meaning {
  font-size: 1.05rem;
  color: #222;
  text-align: left;
  line-height: 1.6;
}
/* 两列布局样式 */
.two-column-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px; /* 调整行距和列距 */
  text-align: left; /* 确保内容靠左对齐 */
}
.two-column-item {
  flex: 1 1 45%; /* 每列占据大约45%宽度，允许换行 */
  font-size: 1.05rem;
  color: #222;
}
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  display: flex;
  align-items: center;
  padding: 0 18px 18px 18px;
  height: 70px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.03);
  z-index: 10;
}
.bottom-left-icon {
  width: 38px;
  height: 38px;
}
.next-btn {
  flex: 1;
  margin-left: 18px;
  height: 44px;
  background: #2979ff;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1.15rem;
  font-weight: bold;
  box-shadow: 0 2px 8px #e3eaff;
}
@media (max-width: 600px) {
  .word-detail-container {
    padding-bottom: 90px;
  }
  .sentence-img {
    max-width: 100%;
  }
  .bottom-bar {
    height: 64px;
    padding-bottom: 10px;
  }
}
</style>
